/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mekegi.whoanthro;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.mekegi.whoanthro.Sql.ChildAdapter;

/**
 *
 * @author Arsen Abdusalamov
 */
public class AddChildActivity extends Activity implements View.OnClickListener {

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstance) {
        super.onCreate(savedInstance);
        setContentView(R.layout.new_childs);
        ((Button)findViewById(R.id.new_child_save_button)).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.new_child_save_button:
                saveChild();
                break;
        }
    }
    /**
     * @since 28.02.13 22:00
     */
    protected void saveChild() {
        Child child = new Child(
            MainActivity.getStringByResId(R.id.child_first_name, this),
            MainActivity.getStringByResId(R.id.child_last_name, this),
            MainActivity.getStringByResId(R.id.child_other_name, this),
            MainActivity.getDateByResId(R.id.child_birthday, this));
        ChildAdapter adapter = new ChildAdapter(this);
        adapter.addItem(child);
        Intent resultIntent = new Intent();
        resultIntent.putExtra(MainActivity.KEY_FOR_RESULT_CHILD_ACTIVITY, child.getId());
        setResult(Activity.RESULT_OK, resultIntent);
        finish();
    }
}
